import Vue from 'vue'
import Router from 'vue-router'
import index from '@/components/index'
import register from '@/components/register'
import login from '@/components/login'
import goodslist from '@/components/goodslist'
import item from '@/components/item'
import comment from '@/components/comment'

Vue.use(Router)

var routes = [
        {
          path:'/',
          name:'index',
          component:index
        },
        {
          path:'/register',
          name:'register',
          component:register
        },
        {
          path:'/login',
          name:'login',
          component:login
        },
        {
          path:'/goodslist',
          name:'goodslist',
          component:goodslist,
          // 拦截器
          beforeEnter: (to, from, next) => {
            if (localStorage.getItem('username')){
              console.log('已登录');
              next();
            } else {
              console.log('未登录');
              next('/login');
            }
          }
        },
        {
          path:'/item',
          name:'item',
          component:item
        },
        {
          path:'/comment',
          name:'comment',
          component:comment
        },
]

export default new Router({
  routes:routes,
  mode:'history'   /*hash*/
})
